package com.seal.yoyoshop.adminweb;

import com.seal.yoyoshop.bin.Order;
import com.seal.yoyoshop.service.OrderService;
import com.seal.yoyoshop.service.impl.OrderServiceImpl;
import com.seal.yoyoshop.util.PageUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "OrderListServlet", value = "/admin/orderList")
public class OrderListServlet extends HttpServlet {

    private OrderService orderService = new OrderServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("flag",1);

        String statusstr = request.getParameter("status");
        Integer status = Integer.parseInt(statusstr);
        request.setAttribute("status",status);
        String pagestr = request.getParameter("page");
        Integer page = Integer.parseInt(pagestr);
        String sizestr = request.getParameter("size");
        Integer size = Integer.parseInt(sizestr);
        List<Order> orderList = null;
        long count = 0;
        if(status == 0){
            orderList = orderService.getOrderList(page, size);
            count = orderService.getOrderCount();
        }else {
            orderList = orderService.getOrderList(status, page, size);
            count = orderService.getOrderCount(status);
        }

        request.setAttribute("orderList",orderList);
        String pageInfo = PageUtil.getPageTool(request, count, page, size);
        request.setAttribute("pageTool",pageInfo);


        request.getRequestDispatcher("/admin/order_list.jsp").forward(request, response);
    }
}
